package com.pigs.pigsordersystem.config;


import com.pigs.pigsordersystem.interceptor.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author PIGS
 *
 * 拦截 未登录的客户
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private UserLoginInterceptor loginInterceptor;

    /**
     * 这个方法用来注册拦截器，写好的拦截器需要通过这里添加注册才能生效
     * 拦截未登录的用户
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        /**
         * 表示拦截所有的请求，
         * addPathPatterns("/**");
         * excludePathPatterns("/login", "/register")
         * 表示除了登陆与注册之外，因为登陆注册不需要登陆也可以访问excludePathPatterns("/login", "/register")
         * showAdminInfo
         *
         */
        registry.addInterceptor(loginInterceptor).addPathPatterns("/finance/buyProducts","/finance/queryOrderList");

    }


}
